<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<head>
    <title>包裹编辑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <script type="text/javascript" src="./js/cookie.js"></script>
</head>

<body>
<script>
    $(function () {
        var url = location.search;
        console.log(url);
        var id=url.split("=")[1];
        var str="http://localhost:8080/package/get_package/"+id;
        $.ajax({
            url:str,
            type:"GET",
            dataType:'JSON',
            contentType : "application/json; charset=utf-8",
            success:function(data){
                if(data.code.code === 0) {
                    var package=data.package;
                    document.getElementById("L_id").value = package.id;
                    document.getElementById("L_sourceNode").value = package.sourceNode;
                    document.getElementById("L_targetNode").value = package.targetNode;
                    document.getElementById("L_createTime").value = package.createTime;
                    var status=package.status;

                    if(status === 0){
                        $("#0").attr("selected","selected");
                    }else if(status === 1){
                        $("#1").attr("selected","selected");
                    } else if(status === 2){
                        $("#2").attr("selected","selected");
                    }
                }
                else{
                    alert(data.code.message);
                }
            },
            error:function () {
                alert("error");
            }
        });
        $("#edit").click(function () {
            var id = $("#L_id").val();
            var sourceNode = $("#L_sourceNode").val();
            var targetNode = $("#L_targetNode").val();
            var createTime = $("#L_createTime").val();
            var status = $("#L_status").val();
            $.ajax({
                url: "http://localhost:8080/package/update" ,
                type: "post",
                dataType: "JSON",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify({
                    "id":id, "sourceNode": sourceNode, "targetNode": targetNode, "createTime": createTime, "status": status
                }),
                success: function (data) {
                    var obj = data;
                    if(obj.code.code === 0){
                        alert("修改成功");
                        x_admin_father_reload();
                        x_admin_close();
                    }
                    else {
                        alert(obj.code.message);
                    }
                },
                error: function () {
                    alert("error");
                }
            });
        });
    });
</script>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="L_id" class="layui-form-label">
                <span class="x-red">*</span>包裹编号
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_id" value="" name="id" required="" lay-verify="id" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_sourceNode" class="layui-form-label">
                <span class="x-red">*</span>源节点
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_sourceNode" name="sourceNode" required="" lay-verify="sourceNode" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_targetNode" class="layui-form-label">
                <span class="x-red">*</span>目的节点
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_targetNode" name="targetNode" required="targetNode" lay-verify="targetNode" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_createTime" class="layui-form-label">
                <span class="x-red">*</span>创建时间
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_createTime" name="createTime" required="createTime" lay-verify="createTime" autocomplete="off" class="layui-input" readonly="readonly">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_status" class="layui-form-label">
                <span class="x-red">*</span>状态
            </label>
            <div class="layui-input-inline">
                <select class="layui-select" id="L_status" name="status" required="status" lay-verify="status">
                    <option id="0"  value="0">新建:0</option>
                    <option id="1"  value="1">打包:1</option>
                    <option id="2"  value="2">转运:2</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button id="edit" type="button"  class="layui-btn" lay-filter="edit" lay-submit="">确认修改</button>
        </div>
    </form>
</div>
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;

        //自定义验证规则
        form.verify({
            id: function(value){
                if(value === '' || value === null){
                    return '包裹编号不能为空';
                }
            }
            ,sourceNode: function(value){
                if(value === '' || value === null){
                    return '源节点不能为空';
                }
            }
            ,targetNode: function(value){
                if(value === '' || value === null){
                    return '目的节点不能为空';
                }
            }
            ,createTime: function(value){
                if(value === '' || value === null){
                    return '创建时间不能为空';
                }
            }
            ,status: function(value){
                if(value === '' || value === null){
                    return '状态不能为空';
                }
            }
        });
    });
</script>
</body>
</html>